﻿<cfsilent>
	<cfscript>
		
		sql = "SELECT 
					t_subject.sbj_name, 
					t_institute.institute_name 
				FROM 
					t_subject 
					INNER JOIN t_institute ON t_institute.institute_id = t_subject.institute_id 
				WHERE 
					t_subject.sbj_direction = '0' 
				ORDER BY 
					t_institute.institute_id, 
					t_subject.level_code ASC, 
					t_subject.term_start ASC, 
					t_subject.sbj_name ASC ";
		queryObj = new query( datasource=application.dnsSlave );
		rs_sub = queryObj.execute( sql=sql ).getResult();
		
		temFile = GetTempDirectory() & createUUID() & ".xls";
		downFile = URLEncodedFormat("培养方案录入模板", "utf-8");
		
		excel = getProperty("serviceFactory").getBean("spreadSheetObject");
		
		/* 创建工作簿 */
		spreadsheetObj = excel.SpreadSheetNew("培养方案", false);
		
		/* 添加表头 */
		excel.SpreadsheetAddrow(spreadsheetObj, "专业,年级,课程号,课程,是否必修,课程类别,开课学期,任课单位,学位课");
		
		/* 添加专业信息参考 */
		excel.SpreadsheetCreateSheet (spreadsheetObj, "专业参考信息");
		excel.SpreadsheetSetActiveSheet (spreadsheetObj, "专业参考信息");
		
		excel.SpreadsheetAddrow(spreadsheetObj, "专业全称,学院");
		
		for ( i=1; i LTE rs_sub.recordCount; i++){
			
			/* 构建部门参考信息 */
			rowData = rs_sub["sbj_name"][i] & "," & rs_sub["institute_name"][i];
			
			/* 写入部门信息 */
			excel.SpreadsheetAddrow(spreadsheetObj, rowData);
			
		}
		
		excel.SpreadsheetSetActiveSheet (spreadsheetObj, "培养方案");
		excel.SpreadSheetWrite(spreadsheetObj, temFile, true);
		
	</cfscript>

	<cfheader name="Content-Disposition" value="attachment; filename=#downFile#.xls" />
	<cfcontent file="#temFile#" reset="yes" type="application/msexcel" deletefile="yes" />	

</cfsilent>